package mq.rabbitmq.b_publish_subscribe;

import com.rabbitmq.client.*;
import mq.rabbitmq.ConnectionUtil;
import mq.rabbitmq.MqConstants;
import mq.rabbitmq.MyDefaultConsumer;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 消费者2
 *
 * @author shanzhenbo
 */
public class Consumer2 {

	public static void main(String[] args) throws IOException, TimeoutException {
		Connection connection = ConnectionUtil.getConnection();
		Channel channel = connection.createChannel();
		channel.exchangeDeclare(MqConstants.FANOUT_EXCHANGE, BuiltinExchangeType.FANOUT);
		channel.queueDeclare(MqConstants.FANOUT_QUEUE_2, true, false, false, null);
		channel.queueBind(MqConstants.FANOUT_QUEUE_2, MqConstants.FANOUT_EXCHANGE, "");
		MyDefaultConsumer myDefaultConsumer = new MyDefaultConsumer(channel, "消费者2");
		channel.basicConsume(MqConstants.FANOUT_QUEUE_2, true, myDefaultConsumer);
	}

}
